#!/usr/bin/env python

import sys
import time

announce_flow_1 = '''\
announce flow route {
	match {
		source 10.0.0.1/32;
		destination 192.168.0.1/32;
		port =80 =8080;
		destination-port >8080&<8088 =3128;
		source-port >1024;
		protocol [ udp tcp ];
	}
	then {
		rate-limit 9600;
	}
}'''.replace('\n','\\n')


announce_flow_2 = '''\
announce flow route {
	match {
		source 10.0.0.2/32;
		destination 10.0.0.3/32;
		destination-port =3128;
		protocol tcp;
	}
	then {
		rate-limit 9600;
	}
}'''.replace('\n','\\n')


withdraw_flow_2 = '''\
withdraw flow route {
	match {
		source 10.0.0.2/32;
		destination 10.0.0.3/32;
		destination-port =3128;
		protocol tcp;
	}
	then {
		rate-limit 9600;
	}
}'''.replace('\n','\\n')


messages = [
'sleep',
announce_flow_2,
withdraw_flow_2,
announce_flow_1,
'sleep',
announce_flow_2,
'sleep',
withdraw_flow_2,
]

while messages:
	message = messages.pop(0)
	if message == 'sleep':
		time.sleep(3)
	else:
		sys.stdout.write( message + '\n')
		sys.stdout.flush()

while True:
	time.sleep(1)

